package com.yourcompany.web.controller;

import cn.dev33.satoken.util.SaResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yourcompany.api.dto.NoticeQueryDTO;
import com.yourcompany.api.entity.SysNotice;
import com.yourcompany.api.service.SysNoticeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@Tag(name = "系统通知管理")
@RestController
@RequestMapping("/api/notice")
public class SysNoticeController {

    @Autowired
    private SysNoticeService noticeService;

    @Operation(summary = "分页查询通知")
    @GetMapping("/page")
    public SaResult pageNotices(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            NoticeQueryDTO queryDTO) {
        Page<SysNotice> page = new Page<>(pageNum, pageSize);
        return SaResult.ok().setData(noticeService.pageNotices(page, queryDTO));
    }

    @Operation(summary = "新增通知")
    @PostMapping
    public SaResult addNotice(@Validated @RequestBody SysNotice notice) {
        noticeService.addNotice(notice);
        return SaResult.ok();
    }

    @Operation(summary = "修改通知")
    @PutMapping
    public SaResult updateNotice(@Validated @RequestBody SysNotice notice) {
        noticeService.updateNotice(notice);
        return SaResult.ok();
    }

    @Operation(summary = "删除通知")
    @DeleteMapping("/{id}")
    public SaResult deleteNotice(@PathVariable Long id) {
        noticeService.deleteNotice(id);
        return SaResult.ok();
    }

    @Operation(summary = "发布通知")
    @PostMapping("/{id}/publish")
    public SaResult publishNotice(@PathVariable Long id) {
        noticeService.publishNotice(id);
        return SaResult.ok();
    }

    @Operation(summary = "撤回通知")
    @PostMapping("/{id}/revoke")
    public SaResult revokeNotice(@PathVariable Long id) {
        noticeService.revokeNotice(id);
        return SaResult.ok();
    }
} 